package cn.homework05;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class MotherDay {
     static Calendar cal;
    static DateFormat df;

    public static void main(String[] args) {
        if(null == args || args.length < 1) {
            System.out.println("请输入年份:");
            return;
        }
        int year;
        try {
            year = Integer.parseInt(args[0]);
        } catch (NumberFormatException e) {
            System.out.println("请输入正确的年份！");
            return;
        }
        df = new SimpleDateFormat("M月dd日");
        cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, 4); // 月份的起始为0
        int maxDate = cal.getActualMaximum(Calendar.DATE);
        int sundays = 0;
        for(int i = 1; i <= maxDate; i ++) {
            cal.set(Calendar.DATE, i);
            if(cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
                sundays ++;
                if(sundays == 2) {
                    break;
                }
            }
        }
        System.out.println(year + "年的母亲节是" + df.format(cal.getTime()));
    }

}